package thread;
//Runnable
public class ThreadDemo10 {
    private static int sum = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                int result = 0;
                for (int i = 1; i <=1000; i++) {
                    result+=i;
                }
                sum=result;
            }
        });
        t.start();
        t.join();
        //主线程想要获取到计算结果,就需要引入一个成员变量保存上述计算结果
        System.out.println("sum = "+sum);
    }
}

